package oj0405.oj0405_01;

import java.util.Scanner;

class CirQueue{
    private static final int QSIZE = 11;
    private int[] data;
    private int head,end;


    public CirQueue() {
//        队头队尾两个指针
        head = QSIZE - 1;
        end = QSIZE - 1;
        data = new int[QSIZE];
    }
//    入队
    public boolean  enQueue(int x){
        if (isFull()){
            System.out.println("Queue is Full");
            return false;
        }
        end = (end + 1) % QSIZE;
        data[end] = x;
        System.out.println("finish");
        return true;
    }

//    出队
    public int  deQueue(){
        if(isEmpty()){
            System.out.println("Queue is Empty");
            return -1;
        }
        head = (head + 1) % QSIZE;
        return data[head];
    }

//    取队头元素
    public int getFront(){
        if (isEmpty()){
            System.out.println("Queue is Empty");
            return -1;
        }
        int x = (head + 1) % QSIZE;
        return data[x];
    }

//    判空
    public boolean isFull(){
        return (end + 1) % QSIZE == head;
    }
    public boolean isEmpty(){
        return head == end;
    }
//    输出队列元素
    public void display(){
        if (isEmpty()){
            System.out.println("Queue is Empty");
            return;
        }
        int x = head;
        while (x != end){
            x = (x + 1) % QSIZE;
            System.out.print(data[x] + ",");
        }
        System.out.println();
    }

//    获取长度
    public int getLength(){
        return (end - head + QSIZE) % QSIZE;
    }

}



public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        CirQueue cirQueue = new CirQueue();
        int row = sc.nextInt();
        int y,res;
        for (int i = 0; i < row; i++) {
            int x= sc.nextInt();
            switch (x){
                case 1:
                    y = sc.nextInt();
                    cirQueue.enQueue(y);
                    break;
                case 2:
                    res = cirQueue.deQueue();
                    if (res != -1){
                        System.out.println(res);
                    }
                    break;

                case 3:
                    res = cirQueue.getFront();
                    if (res != -1){
                        System.out.println(res);
                    }
                    break;
                case 4:
                    System.out.println(cirQueue.getLength());
                    break;
                case 5:
                    cirQueue.display();
                    break;
                default:
                    break;
            }
        }
    }
}
